<?php

namespace app\crontab\task;

use app\common\behavior\DealerMoney;
use app\common\model\zbtask\Money;
use think\Db;


/**
 * 计划的定时任务 
 */ 
class Dealer extends Common
{
    const BACK_TIME = 'last week';
    /**反佣金*/
    public function back() {
        $where['transfer_type'] = 2; //打款成功
        $where['status'] = 1; //有效
        $where['is_back'] = 0;
        Money::where($where)->whereTime('pay_time', self::BACK_TIME)->chunk(1000, function($lists)  {
            foreach ($lists as $k => $v) {
               try {
                    DealerMoney::dealerBack($v['id']);
                    $v->is_back = 1;
                    $v->save();
               } catch (\Exception $e) {
                   $str = '众包费'. $v['id'] . '修改back状态失败';
                    doLog($str, 'dealerlogback');
               }
            }
        });
    }
}